<!--
 create.xhtml

 Copyright 2009 Jack Leow

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets">
  <head>
    <title>Create Search Provider</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="css/main.css" type="text/css" />
    <ui:fragment rendered="#{searchProvider.complete}">
      <link rel="search" type="application/opensearchdescription+xml" href="open-search.jsf?#{request.queryString}" title="#{searchProvider.name}" />
    </ui:fragment>
  </head>
  <body>
    <f:view contentType="text/html; charset=UTF-8">
      <f:loadBundle basename="my.edu.clhs.customsearchprovider.Messages" var="msg" />
      <f:metadata>
        <f:viewParam name="name" value="#{searchProvider.name}" />
        <f:viewParam name="searchTemplate" value="#{searchProvider.searchQueryUrlTemplate}" />
        <f:viewParam name="suggestionTemplate" value="#{searchProvider.searchSuggestionUrlTemplate}" />
        <f:viewParam name="icon" value="#{searchProvider.searchIconUrl}" />
      </f:metadata>
      <h1>Create Search Provider</h1>
      <div>Some examples:
        <ul>
          <li>
            <h:link outcome="create" value="Google (Omitting Certain Domains)">
              <f:param name="name" value="Google (Custom)" />
              <f:param name="searchTemplate" value="http://www.google.com/search?ie=utf-8&amp;oe=utf-8&amp;aq=t&amp;q={searchTerms}+-site:experts-exchange.com" />
              <f:param name="suggestionTemplate" value="http://suggestqueries.google.com/complete/search?output=firefox&amp;qu={searchTerms}" />
              <f:param name="icon" value="http://www.google.com/favicon.ico" />
            </h:link>
          </li>
          <li>
            <h:link outcome="create" value="Google (Code Search)">
              <f:param name="name" value="Google (Code Search)" />
              <f:param name="searchTemplate" value="http://www.google.com/codesearch?q={searchTerms}&amp;hl=en" />
              <f:param name="suggestionTemplate" value="" />
              <f:param name="icon" value="http://www.google.com/favicon.ico" />
            </h:link>
          </li>
          <li>
            <h:link outcome="create" value="Yahoo! Finance">
              <f:param name="name" value="Yahoo! Finance" />
              <f:param name="searchTemplate" value="http://finance.yahoo.com/q?d=t&amp;s={searchTerms}" />
              <f:param name="suggestionTemplate" value="" />
              <f:param name="icon" value="http://www.yahoo.com/favicon.ico" />
            </h:link>
          </li>
          <li>
            <h:link outcome="create" value="eBay Details">
              <f:param name="name" value="eBay Details" />
              <f:param name="searchTemplate" value="http://search-desc.ebay.com/search/search.dll?srchdesc=y&amp;query={searchTerms}" />
              <f:param name="suggestionTemplate" value="" />
              <f:param name="icon" value="http://www.ebay.com/favicon.ico" />
            </h:link>
          </li>
        </ul>
      </div>
      <div class="form">
        <h:form>
          <div class="formField">
            <div class="formFieldLabel">
              <label for="name">Name:</label>
            </div>
            <div class="formFieldInput">
              <h:inputText id="name"
                           value="#{searchProvider.name}"
                           required="true"
                           requiredMessage="#{msg['required.searchProvider.name']}" />
              <h:message for="name" errorClass="errorMessage" />
            </div>
          </div>

          <div class="formField">
            <div class="formFieldLabel">
              <label for="searchTemplate">Search Query URL Template:</label>
            </div>
            <div class="formFieldInput">
              <h:inputText id="searchTemplate"
                           value="#{searchProvider.searchQueryUrlTemplate}"
                           required="true"
                           requiredMessage="#{msg['required.searchProvider.searchQueryUrlTemplate']}"
                           validatorMessage="#{msg['typeMismatch.searchProvider.searchQueryUrlTemplate']}"
                           size="60">
                <f:validateRegex for="searchTemplate" pattern="^https?://[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)*/.*\{searchTerms\}.*$" />
              </h:inputText>
              <h:message for="searchTemplate" errorClass="errorMessage" />
            </div>
          </div>

          <div class="formField">
            <div class="formFieldLabel">
              <label for="suggestionTemplate">Search Suggestion URL Template:</label>
            </div>
            <div class="formFieldInput">
              <h:inputText id="suggestionTemplate"
                           value="#{searchProvider.searchSuggestionUrlTemplate}"
                           validatorMessage="#{msg['typeMismatch.searchProvider.searchSuggestionUrlTemplate']}"
                           size="60">
                <f:validateRegex for="suggestionTemplate" pattern="^(|https?://[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)*/.*\{searchTerms\}.*)$" />
              </h:inputText>
              <h:message for="suggestionTemplate" errorClass="errorMessage" />
            </div>
          </div>

          <div class="formField">
            <div class="formFieldLabel">
              <label for="icon">Search Icon URL (16x16 only):</label>
            </div>
            <div class="formFieldInput">
              <h:inputText id="icon"
                           value="#{searchProvider.searchIconUrl}"
                           validatorMessage="#{msg['typeMismatch.searchProvider.searchIconUrl']}"
                           size="60">
                <f:validateRegex for="icon" pattern="^(|https?://[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)*/.*)$" />
              </h:inputText>
              <h:message for="icon" errorClass="errorMessage" />
            </div>
          </div>

          <div class="formField">
            <div class="formFieldLabel">&#160;</div>
            <div class="formFieldInput">
              <h:commandButton action="create" value="Create" />
            </div>
          </div>
        </h:form>
      </div>
      <ui:fragment rendered="#{searchProvider.complete}">
        <hr />
        <div>
          <h:link outcome="openSearch" includeViewParams="true" value="Download Open Search XML Descriptor" /><br />
          <script type="text/javascript">
            var href = window.location.href;
            var baseUrl = href.substring(0, href.lastIndexOf("/") + 1);
            var queryString = window.location.search;
            var openSearchUrl = baseUrl + "open-search.jsf" + queryString;
          </script>
          <a href="javascript:window.external.AddSearchProvider(openSearchUrl);">Add to Browser Search Box</a>
        </div>
      </ui:fragment>
      <hr />
      <p>Copyright © 2009-<h:outputText value="#{globals.currentTime}"><f:convertDateTime pattern="yyyy" /></h:outputText> by Jack Leow. All Rights Reserved.</p>
      <script type="text/javascript">
        var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
        document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
      </script>
      <script type="text/javascript">
        try {
          var pageTracker = _gat._getTracker("UA-5685732-4");
          pageTracker._trackPageview();
        } catch(err) {}</script>
    </f:view>
  </body>
</html>